﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：Program.cs
// 功能描述：TongTongMall.RabbitMq.ProducerTest
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Newtonsoft.Json;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TongTongMall.RabbitMq.ProducerTest
{
    public class MessageData
    {
        /// <summary>
        /// 命令名称
        /// </summary>
        public string CommandName { get; set; }

        /// <summary>
        /// 消息内容实体
        /// </summary>
        public object MessageDataBody { get; set; }
    }

    public class RedisContinueEventData
    {
        /// <summary>
        /// key值
        /// </summary>
        public string Keys { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        public object Data { get; set; }
    }

    class Program
    {

        private static string exchangeName = "TongTongMall.Web.CommandMessageExchange";
        public static void Main()
        {
            
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange: exchangeName, type: "fanout");
                var message = new MessageData {
                    CommandName = "RedisContinueEventData",
                    MessageDataBody = new RedisContinueEventData { Keys = "11", Data = "sss" }
                };
                var json = JsonConvert.SerializeObject(message, Formatting.Indented);
                var bytes = Encoding.UTF8.GetBytes(json);

                channel.BasicPublish(exchange: exchangeName, routingKey: "", basicProperties: null, body: bytes);
            }

        }

        /// <summary>
        /// Assumes only valid positive integer input.
        /// Don't expect this one to work for big numbers,
        /// and it's probably the slowest recursive implementation possible.
        /// </summary>
        private static int fib(int n)
        {
            if (n == 0 || n == 1)
            {
                return n;
            }

            return fib(n - 1) + fib(n - 2);
        }
    }
}
